package com.example.officialdocumentsys.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.officialdocumentsys.annotation.LogAnno;
import com.example.officialdocumentsys.common.R;
import com.example.officialdocumentsys.po.Org;
import com.example.officialdocumentsys.po.User;
import com.example.officialdocumentsys.service.OrgService;
import com.example.officialdocumentsys.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 * 组织 前端控制器
 * </p>
 *
 * @author hi
 * @since 2022-11-23
 */
@RestController
@RequestMapping("/org")
public class OrgController extends BaseController<Org, OrgService>{

    @Autowired
    private UserService userService;

    @LogAnno(operateType = "删除组织")
    @DeleteMapping
    public R<String> delete(@RequestParam List<Serializable> ids) {
        //构造函数
        QueryWrapper<User> userQueryWrapper = new QueryWrapper<>();
        userQueryWrapper.lambda().in(User::getCategoryId,ids);
        if (userService.count(userQueryWrapper) > 0){
            return R.error("请先删除组织中的用户");
        }
        baseService.removeByIds(ids);
        return R.success("删除成功");
    }

}

